package com.heer.gymnasium.fragment;

import android.os.Handler;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.heer.api.ResponseData.ApiResponse;
import com.heer.api.callback.BaseCallback;
import com.heer.api.constants.IConstants;
import com.heer.api.sign.SDKRuntimeException;
import com.heer.api.sign.SignHelper;
import com.heer.gymnasium.R;
import com.heer.gymnasium.activity.OrderSuppleActivity;
import com.heer.gymnasium.adapter.ChuruListAdapter;
import com.heer.gymnasium.adapter.MyPagerAdapter;
import com.heer.gymnasium.dialog.SiteLevelDialog;
import com.heer.gymnasium.event.BaseEvent;
import com.heer.model.ChuRuOrderBean;
import com.heer.model.OrderBean;
import com.heer.model.OrderStatusBean;
import com.heer.model.QrcodeAccess;
import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayout;
import com.zbar.lib.utils.QRImageUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import cn.trinea.android.view.autoscrollviewpager.AutoScrollViewPager;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

import static com.heer.gymnasium.event.EventConstant.CANCEL_ORDER;
import static com.heer.gymnasium.event.EventConstant.CREATE_ORDER;

/**
 * Created by rzw2 on 2017/4/5.
 */

public class MainAccessFragment extends BaseRefreshFragment {

    @BindView(R.id.list)
    ListView lv_churu;

    @BindView(R.id.layout_refresh)
    SwipyRefreshLayout sr_access;

    ChuruListAdapter mAdapter;

    @Override
    protected int setConvertView() {
        return R.layout.fragment_main_access;
    }

    @Override
    protected void init() {
        super.init();

    }

    @Override
    protected void initView() {
        super.initView();

        mAdapter=new ChuruListAdapter(getContext());
        lv_churu.setAdapter(mAdapter);
        sr_access.setOnRefreshListener(this);


    }

    @Override
    protected void loadData(final boolean loadmore) {

        SignHelper sign = new SignHelper("");

            mAppHelper.apiService().getChuRuOrder( sign.GetParameter("token")).enqueue(new BaseCallback<ApiResponse<List<ChuRuOrderBean>>>() {
                @Override
                public void onResponse(Call<ApiResponse<List<ChuRuOrderBean>>> call, Response<ApiResponse<List<ChuRuOrderBean>>> response) {
                    super.onResponse(call, response);
                    sr_access.setRefreshing(false);
                    if (response.isSuccessful() && response.body().isSccessful()) {


                        if (loadmore)
                        {
                            mAdapter.setItems(response.body().getData());
                        }else {
                            mAdapter.clearItems();
                            mAdapter.setItems(response.body().getData());
                        }

                    }
                }
            });


    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();

    }



}
